import json
from datetime import datetime
from urllib import parse
from flask import Flask, Response
import requests
from flask import request
from retrying import retry





class AreaApManagerApis:



    @retry(stop_max_attempt_number=5, wait_fixed=2000)
    @staticmethod
    def v1_aapmgr_handler(method, url, request_json,request_args):
        """
        公共处理
        :return:
        """
        session = requests.session()
        resp = session.request(method=method,url=url, json=request_json,data=request_args)
        if resp.status_code != 200:
            raise
        return resp.status_code,resp.json()

    @retry(stop_max_attempt_number=5, wait_fixed=2000)
    @staticmethod
    def v1_status_handler(method, url, request_json,request_args):
        """
        公共处理
        :return:
        """
        session = requests.session()
        resp = session.request(method=method,url=url, json=request_json,data=request_args)
        if resp.status_code != 200:
            raise
        return resp.status_code,resp.json()


    @retry(stop_max_attempt_number=5, wait_fixed=2000)
    @staticmethod
    def v1_config_handler(method, url, request_json,request_args):
        """
        公共处理
        :return:
        """
        session = requests.session()
        resp = session.request(method=method,url=url, json=request_json,data=request_args)
        if resp.status_code != 200:
            raise
        return resp.status_code,resp.json()



    @retry(stop_max_attempt_number=5, wait_fixed=2000)
    @staticmethod
    def v1_db_handler(method, url, request_json,request_args):
        """
        公共处理
        :return:
        """
        session = requests.session()
        resp = session.request(method=method,url=url, json=request_json,data=request_args)
        if resp.status_code != 200:
            raise
        return resp.status_code,resp.json()